﻿Imports System.Collections.Generic
Imports System.Linq
Partial Class bo_SearchEditCustomer
    Inherits System.Web.UI.Page
    Public SearchBy As String
    Public SearchStr As String

   
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        SearchBy = ddSearchBy.SelectedValue.ToString()
        SearchStr = txtStr.Text.ToString()

        


    End Sub

    Protected Sub btnShowCustDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowCustDetails.Click
        panelDetails.Visible = True
        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim custId As Integer = hfldCustID.Value
    
        Dim custList As List(Of OneCall.DataModel.Customer) = (From p In SQLDB.Customers Where p.Customer_ID = custId).ToList()

        Dim custDetails As OneCall.DataModel.Customer = custList(0)

        Dim subList As List(Of OneCall.DataModel.viewCustomerSubscription) = (From p In SQLDB.viewCustomerSubscriptions Where p.Customer_ID = custId).ToList()


        lblDateTime.Text = custDetails.Customer_DateTime.ToString()
        lblUsername.Text = custDetails.Customer_UserName
        lblFirstName.Text = custDetails.Customer_FirstName
        lblLastName.Text = custDetails.Customer_LastName
        lblEmail.Text = custDetails.Customer_EmailID
        lblMobile.Text = custDetails.Customer_Mobile
        lblAddress.Text = custDetails.Customer_Address
        lblCity.Text = custDetails.Customer_City
        lblState.Text = custDetails.Customer_State
        lblCountry.Text = custDetails.Customer_Country
        lblPin.Text = custDetails.Customer_Pin

        If custDetails.Customer_AcStatus = 0 Then
            lblStatus.Text = "Not verified"
            btnStatus.Text = "Verify"
        Else
            lblStatus.Text = "Verified"
            btnStatus.Visible = False
        End If

        If subList.Count >= 1 Then
            Dim SubDetail As OneCall.DataModel.viewCustomerSubscription = subList(0)
            Dim dateD As Integer = DateAndTime.DateDiff(DateInterval.Day, Now, CDate(SubDetail.Membership_EndDate))
            lblSubType.Text = SubDetail.Subscription_Name
            lblSubStart.Text = SubDetail.Membership_StartDate
            lblSubEnd.Text = SubDetail.Membership_EndDate
            lblSubAmount.Text = "Rs." & SubDetail.Subscription_Amount
            lblSubDays.Text = dateD & " days"
        Else
            lblSubType.Text = ""
            lblSubStart.Text = ""
            lblSubEnd.Text = ""
            lblSubAmount.Text = ""
            lblSubDays.Text = ""
        End If


        SQLDB.Dispose()

    End Sub

    Protected Sub btnStatus_Click(sender As Object, e As System.EventArgs) Handles btnStatus.Click
        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim custId As Integer = hfldCustID.Value
        Dim custList As List(Of OneCall.DataModel.Customer) = (From p In SQLDB.Customers Where p.Customer_ID = custId).ToList()
        Dim custDetails As OneCall.DataModel.Customer = custList(0)
        custDetails.Customer_AcStatus = 1
        SQLDB.SaveChanges()
        SQLDB.Dispose()
        lblStatus.Text = "Verified"
        btnStatus.Visible = False
    End Sub
End Class
